package com.spider.admin.controller;

import com.spider.admin.exception.SpiderException;
import com.spider.admin.http.entity.PageResult;
import com.spider.admin.service.agent.AgentSettingService;
import com.spider.admin.store.primary.model.AgentSettingInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/agentSetting")
public class AgentSettingController {

    @Autowired
    private AgentSettingService agentSettingService;

    @GetMapping("/list/{section}")
    public PageResult<AgentSettingInfo> queryAgentSettingList(
            @PathVariable String section,
            @RequestParam(required = false) Integer currentPage,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String optionItem,
            @RequestParam(required = false) String belongType,
            @RequestParam(required = false) String belongId) throws SpiderException {
        return agentSettingService.queryAgentSettingList(currentPage, pageSize, section, optionItem, belongType, belongId);
    }

    @PostMapping("/save")
    public int saveAgentSetting(@RequestBody AgentSettingInfo agentSettingInfo) throws SpiderException {
        return agentSettingService.saveSetting(agentSettingInfo);
    }

    @GetMapping("/serverTreeDate")
    public List<Map<String, String>> getAgentServerList(@RequestParam(required = false) String tenantId,@RequestParam(required = false) Integer roleType) throws SpiderException {
        return agentSettingService.queryAgentServerList(tenantId,roleType);
    }

    @GetMapping("/serverTreeDate2")
    public List<Map<String, String>> getAgentServerList2(@RequestParam(required = false) String tenantId,@RequestParam(required = false) Integer roleType) throws SpiderException {
        return agentSettingService.queryAgentServerList2(tenantId,roleType);
    }
}
